﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using GWEB.WebBase.Data;
using GWEB.WebBase.Entity;
using GWEB.WebBase.Utility;
using GWEB.WebFrame.Public;

namespace GWEB.WebFrame.Schedule
{
    public class GroupController : PageInfoBase
    {
        [ActionFilter(IsLogin = true)]
        public ActionResult Index(String id, String keyCode)
        {
            return Load("Group", "Schedule/Group", id, keyCode);
        }       
        
        protected override SqlState SqlExecute(BaseData bd, String id, Dictionary<String, Object> data)
        {
            if (id.Equals("-1")) {
                DataRow drUser = BasePage.GetUser(Session);
                data["LeagueId"] = drUser["LeagueId"];
                data["CreateId"] = drUser["iUserId"];
                data["CreateDate"] = DateTime.Now;
            }
            return SqlState.None;
        }
        //将学员增加到小组中
        [ActionFilter(IsJson = true)]
        public JsonResult AddToGroup(String id, String keyCode, String gId)
        {
            if (!Fun.IDVerify(id, keyCode))
                return BasePage.Json(ResultData.Error(WebMessage.NoGrant));            
            String sql = String.Format(@"insert into cu_Cus_Group_Detail(cid,groupId) select {0},{1} where not exists(select * from cu_Cus_Group_Detail where cid={0} and groupId={1})", id, gId);
            bool t = BasePage.bd.ExecuteSQL(sql);
            return BasePage.Json(t ? ResultData.OK("加入成功") : ResultData.Error("加入失败"));
        }
       
    }
}